/**
 * 
 */
package com.util;


/**
 * @author 663606
 *
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


// import java.sql.Statement;

public class DBConnection {
	public static Connection Connect() 
	{	
		Connection conn =null;
		try 
		{
			
			Class.forName("org.hsqldb.jdbc.JDBCDriver");
			conn = DriverManager.getConnection("jdbc:hsqldb:mydb", // filenames
					"SA", // username
					""); // password
			
			System.out.println("Connection Established  !! : "+conn);	
			return conn;
		}
		
		catch ( ClassNotFoundException cnfex ) 
		{
			System.out.println("Class not found !! " +cnfex);
			return null;
		}
		catch ( SQLException sqlex ) 
		{
			System.out.println("SQL Exception !! " +sqlex);
			System.out.println("Running Stack Trace : ");
			sqlex.printStackTrace();
			return null;
		}
		catch (Exception ex)
		{
			System.out.println("Exception has occured "+ex);
			return null;
		}
		/*finally {
			// Close down
			try {
			if (null != statement){
				statement.close();				
			}
			if (null != conn){
				conn.close();				
			}
			} catch (SQLException e){			
			}
		}*/
		
	}

	public static boolean validateConnection(Connection connObj)
	{
		if (connObj == null) {
			System.out
					.println("Sorry. We could not connect to the Server. \n Try again later ! ");
			return false;

		} else {
			System.out.println("Server Connected.... ! ");
			System.out.println("Connection Object Details :");
			System.out.println(connObj);
			return true;
		}
	}
}
